package com.jack.vipmis.vip.wei.service;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import com.jack.vipmis.common.entity.search.SearchOperator;
import com.jack.vipmis.common.entity.search.Searchable;
import com.jack.vipmis.common.service.BaseService;
import com.jack.vipmis.vip.wei.entity.Replytribune;
import com.jack.vipmis.vip.wei.repository.ReplyTribuneRepository;

/**
 * 
 * @author JackLiang
 * @date 2014-6-15
 * @version 1.0
 */
@Service
public class ReplyTribuneService extends BaseService<Replytribune, Long> {

	private ReplyTribuneRepository getReplyTribuneRepository() {
		return (ReplyTribuneRepository) baseRepository;
	}

	public Replytribune findByTribune(Long tid) {
		return getReplyTribuneRepository().findByTribune(tid);
	}

	/**
	 * 
	 * @param page
	 * @param pageSize
	 * @param tid
	 * @return
	 */
	public Page<Replytribune> getReplyListByPageAndTid(int page, int pageSize, long tid) {
		Searchable searchable = buildSearchable(page, pageSize, tid);
		return getReplyTribuneRepository().findAll(searchable);
	}

	/**
	 * 构建查询条件
	 * 
	 * @param page
	 * @param pageSize
	 * @param tid
	 * @return
	 */
	private Searchable buildSearchable(int page, int pageSize, long tid) {
		Searchable searchable = Searchable.newSearchable();
		searchable.addSearchFilter("tribune", SearchOperator.eq, tid);
		searchable.addSort(Direction.DESC, "reTime");
		searchable.setPage((page - 1), pageSize);
		return searchable;
	}
}
